package com.yowasa.xiuxian.engine.battle.strategy.drop.soild;

import com.yowasa.xiuxian.annoations.BS;
import com.yowasa.xiuxian.constant.XiuxianConstants;
import com.yowasa.xiuxian.engine.battle.strategy.BaseSpellStrategy;
import com.yowasa.xiuxian.entity.bo.battle.BattleContent;
import com.yowasa.xiuxian.entity.bo.battle.UserBattleContent;
import com.yowasa.xiuxian.entity.bo.user.UserBO;
import com.yowasa.xiuxian.entity.enums.ElementEnum;
import com.yowasa.xiuxian.exception.HandlerException;
import com.yowasa.xiuxian.service.helper.BattleHelper;
import com.yowasa.xiuxian.util.RandomUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

@BS(name="创生法拟造阳华")
@Order(501)
@Component
public class ChuangShengNiZaoYangHua extends BaseSpellStrategy {
    @Autowired
    private BattleHelper battleHelper;
    @Override
    public ElementEnum getElement() {
        return ElementEnum.SOIL;
    }

    @Override
    public void action(UserBattleContent first, UserBattleContent second, BattleContent content) {
        int orgAtk = first.getBattleInfo().getAtk() + first.getBattleInfo().getDef() / 2;
        int def = second.getBattleInfo().getDef();
        int costMp = (first.getBattleInfo().getAtk() + first.getBattleInfo().getSpell())/2;
        int dmg = battleHelper.calSpell(orgAtk,def);
        first.getBattleInfo().setCmp(first.getBattleInfo().getCmp() - costMp);
        battleHelper.autoAction(this, first, second, content, dmg, "创生法拟造阳华");
        first.getCd().put("创生法拟造阳华", 3);
    }

    @Override
    public void limit(UserBO user) {
        if (user.getElement().get("土") < XiuxianConstants.DEFAULT_ELEMENT_ACTIVITY) {
            throw new HandlerException("学习/使用创生法拟造阳华必须具有土灵根");
        }
    }
    @Override
    public String limitDesc() {
        return "具有土灵根";
    }

    @Override
    public String desc() {
        return "以岩元素炼成阳华催生的刹那之花，随着你的攻击而绽放，使本次攻击额外造成物抗一半的伤害\n消耗等同物攻+法攻一半的mp，cd 2回合";
    }

    @Override
    public boolean check(UserBattleContent user, BattleContent content) {
        Integer cd = user.getCd().get("创生法拟造阳华");
        if (cd != null && cd > 0) {
            return false;
        }
        int costMp = (user.getBattleInfo().getSpell() + user.getBattleInfo().getAtk())/2;
        if (user.getBattleInfo().getCmp() < costMp) {
            return false;
        }
        return true;
    }
}
